package com.xubeizhi.controller.system;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xubeizhi.annotation.OperationLogger;
import com.xubeizhi.common.ResponseResult;
import com.xubeizhi.entity.Page;
import com.xubeizhi.service.PageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 控制器
 * @author mi
 * @create 2023/3/16 20:47
 */
@RestController
@RequestMapping("/system/page")
@Api(value = "后台页面管理")
@RequiredArgsConstructor
public class PageController {
    private final PageService pageService;

    @GetMapping(value = "/list")
    @SaCheckLogin
    @ApiOperation(value = "页面列表",httpMethod = "GET",response = ResponseResult.class,notes = "页面列表")
    public ResponseResult list(){
        return pageService.listPage();
    }

    @PostMapping(value = "/add")
    @SaCheckPermission("/system/page/add")
    @ApiOperation(value = "添加页面",httpMethod = "POST",response = ResponseResult.class,notes = "添加页面")
    @OperationLogger(value = "添加页面")
    public ResponseResult insert(@RequestBody Page page){
        return pageService.insertPage(page);
    }

    @PostMapping("/update")
    @SaCheckPermission("/system/page/update")
    @ApiOperation(value = "修改页面",httpMethod = "POST",response = ResponseResult.class,notes = "修改页面")
    @OperationLogger(value = "修改页面")
    public ResponseResult update(@RequestBody Page page){
        return pageService.updatePage(page);
    }

    @DeleteMapping("/delete")
    @SaCheckPermission("/system/page/delete")
    @ApiOperation(value = "删除页面",httpMethod = "DELETE",response = ResponseResult.class,notes = "删除页面")
    @OperationLogger(value = "删除页面")
    public ResponseResult deleteById(Long id){
        return pageService.deleteById(id);
    }
}
